<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="nameTxt">
        <el-input v-model="queryParams.nameTxt" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="所属部门" prop="departmentName">

<el-select
      v-model="queryParams.departmentName"
      placeholder="请选择部门"  style="width:100%"
    >
      <el-option v-for="item in deptlist" :key="item.deptId" :value="item.deptId" :label="item.deptName"/>
    </el-select>
</el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['hrmanagement:tracking:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['hrmanagement:tracking:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['hrmanagement:tracking:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['hrmanagement:tracking:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="trackingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="nameTxt" />
      <el-table-column label="部门名称" align="center" prop="departmentNameTxt" />
      <el-table-column label="目标名称" align="center" prop="targetName" />
      <el-table-column label="计划完成日" align="center" prop="dueDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dueDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="行动步骤" align="center" prop="actionSteps" />
      <el-table-column label="完成率" align="center" prop="completionRate" >
        <template slot-scope="scope">
          <el-progress :percentage="scope.row.completionRate"></el-progress>     
           </template>
      </el-table-column>
      <el-table-column label="完成情况说明" align="center" prop="completionNotes" />
      <el-table-column label="目标状态" align="center" prop="targetStatus" >
        <template slot-scope="scope">
          <el-tag :type="scope.row.targetStatus==='准备中'?'success':'earning'" >{{ scope.row.targetStatus }}</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['hrmanagement:tracking:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['hrmanagement:tracking:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改个人计划表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="姓名" prop="name">
<el-select v-model="form.name"  placeholder="请选择" @focus="useropen">
    <el-option
    placeholder="请选择用户"
      v-for="item in useroptions"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
        </el-form-item>


        <el-row>

          <el-col :span="12">
            <el-form-item label="所属部门" prop="departmentName">



<el-select
    v-model="form.departmentName"
    placeholder="请选择部门"  style="width:100%"
  >
    <el-option v-for="item in deptlist" :key="item.deptId" :value="item.deptId" :label="item.deptName"/>
  </el-select>
</el-form-item>


          </el-col>
          <el-col :span="12">
            <el-form-item label="具体目标" prop="targetName">
          <el-input v-model="form.targetName" placeholder="请输入具体目标" />
        </el-form-item>


          </el-col>
          <el-col :span="12">
            <el-form-item label="计划完成日" prop="dueDate">
          <el-date-picker clearable v-model="form.dueDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择计划完成日期">
          </el-date-picker>
        </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="完成率" prop="completionRate">

<el-input  type="number" v-model="form.completionRate" placeholder="请输入完成率">
        <span slot="suffix">%</span>
      </el-input>



</el-form-item>

          </el-col>
        </el-row>
      

       
      
        <el-form-item label="行动步骤" prop="actionSteps">
          <el-input class="area" v-model="form.actionSteps" type="textarea" placeholder="请输入内容"  />
        </el-form-item>
        
        <el-form-item label="完成情况说明" prop="completionNotes">
          <el-input v-model="form.completionNotes" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="目标状态" prop="targetStatus">

          <el-radio-group v-model="form.targetStatus">
       
                  <el-radio label="执行中">执行中</el-radio>
                  <el-radio label="已完成">已完成</el-radio>
                </el-radio-group>

        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTracking, getTracking, delTracking, addTracking, updateTracking } from "@/api/hrmanagement/tracking";
import UserSelect from "@/components/PeopleSelect/index";
import { getUserSelect } from "@/api/system/user";
import { AllDept } from "@/api/system/dept";
export default {
  name: "Tracking",
  data() {
    return {
      userOpen:false,
      useroptions: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 个人计划表表格数据
      trackingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      deptlist:[],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nameTxt: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "姓名或标识，代表参与者的名称不能为空", trigger: "blur" }
        ],
        targetName: [
          { required: true, message: "目标名称，描述要达到的具体目标不能为空", trigger: "blur" }
        ],
        dueDate: [
          { required: true, message: "计划完成日，目标的预期完成日期不能为空", trigger: "blur" }
        ],
        targetStatus: [
          { required: true, message: "目标状态，表示目标的当前状态，如待处理、进行中或已完成不能为空", trigger: "change" }
        ],
        nameTxt: [
          { required: true, message: "姓名或标识，代表参与者的名称不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    AllDept().then(response => {
          if (response.code === 200) {
            this.deptlist= response.data
          } else {
            this.$message.error(response.message)
          }
        })
  },
  methods: {
    submituser(peopleList){
  

      this.form.name  = parseInt(peopleList.join(""))

 this.$forceUpdate()
        this.userOpen=false;
      },
      useropen(){

        this.userOpen=true;
       },
    /** 查询个人计划表列表 */
    getList() {
      this.loading = true;
      listTracking(this.queryParams).then(response => {
        this.trackingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      getUserSelect().then(response => {
        this.useroptions = response.data
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        targetName: null,
        dueDate: null,
        actionSteps: null,
        completionRate: null,
        completionNotes: null,
        targetStatus: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        nameTxt: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加个人计划表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTracking(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改个人计划表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTracking(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTracking(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除个人计划表编号为"' + ids + '"的数据项？').then(function () {
        return delTracking(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hrmanagement/tracking/export', {
        ...this.queryParams
      }, `tracking_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>

.area{
  height: 150px;


}
.el-textarea ::v-deep textarea{
  height: 140px;
}
</style>